using BasicScript.Component;
using Game.Main.Model;
using Game.XH;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class NumberCardItem : BaseItem
	{
		private int num;

		private SpriteRenderer[] nums;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			nums = new SpriteRenderer[2];
			nums[0] = model.Find("0").GetComponent<SpriteRenderer>();
			nums[0].transform.SetLocalZ(-1E-05f);
			nums[1] = model.Find("1").GetComponent<SpriteRenderer>();
			nums[1].transform.SetLocalZ(-1E-05f);
			if (data.state != 0)
			{
				InitNumber(data.state);
			}
		}

		public void InitNumber(int val)
		{
			if (val > 0 && val < 100)
			{
				num = val;
				string[] array = new string[2];
				if (val < 10)
				{
					array[0] = "0";
					array[1] = val.ToString();
				}
				else
				{
					array[0] = num.ToString().Substring(0, 1);
					array[1] = num.ToString().Substring(1, 1);
				}
				SpriteAssets component = model.GetComponent<SpriteAssets>();
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i];
					nums[i].sprite = component.GetSprite(text);
				}
			}
		}

		public int GetNum()
		{
			return num;
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = num;
		}
	}
}
